package com.fhminyi.GUI;

import com.fhminyi.dao.ProductDao;
import com.fhminyi.model.Product;
import com.fhminyi.model.User;
import com.fhminyi.util.ImageUploadSelector;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class EditProductFrame extends JFrame {

    private User currentUser;
    private List<Product> products;

    public EditProductFrame(User currentUser, List<Product> products) {
        this.currentUser = currentUser;
        this.products = products;
        setTitle("编辑商品");
        setSize(600, 400);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setLocationRelativeTo(null);

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 2));

        for (Product product : products) {
            JLabel nameLabel = new JLabel(product.getProductName());
            JButton editButton = new JButton("编辑");

            editButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    new EditProductDetailFrame(currentUser, product).setVisible(true);
                }
            });

            panel.add(nameLabel);
            panel.add(editButton);
        }

        add(panel);
    }
}